CC=g++
CFLAGS=-Wall -pedantic -pedantic-errors -g -ggdb -DDEBUG
LDFLAGS=
BINF=../bin
HEADER_DIR=..

SHARED_SOURCES := $(shell find ../*/ -name '[Logger|Semaphore]*.cpp')
SHARED_OBJ=$(SHARED_SOURCES:.cpp=.o)

BROKER_SOURCES=Broker.cpp
BROKER_OBJ=$(BROKER_SOURCES:.cpp=.o)
BROKER_BIN=$(BINF)/initBroker

BROKER_PASA_MANOS_EMISOR_SOURCES=brokerPasamanosEmisor.cpp
BROKER_PASA_MANOS_EMISOR_OBJ=$(BROKER_PASA_MANOS_EMISOR_SOURCES:.cpp=.o)
BROKER_PASA_MANOS_EMISOR_BIN=$(BINF)/brokerPasamanosEmisor

BROKER_PASA_MANOS_RECEPTOR_SOURCES=brokerPasamanosReceptor.cpp
BROKER_PASA_MANOS_RECEPTOR_OBJ=$(BROKER_PASA_MANOS_RECEPTOR_SOURCES:.cpp=.o)
BROKER_PASA_MANOS_RECEPTOR_BIN=$(BINF)/brokerPasamanosReceptor

BROKER_REQ_DISP_SOURCES=brokerRequerimientosDisp.cpp
BROKER_REQ_DISP_OBJ=$(BROKER_REQ_DISP_SOURCES:.cpp=.o)
BROKER_REQ_DISP_BIN=$(BINF)/brokerRequerimientosDisp

BROKER_REQ_TEST_ESP_SOURCES=brokerReqEspeciales.cpp
BROKER_REQ_TEST_ESP_OBJ=$(BROKER_REQ_TEST_ESP_SOURCES:.cpp=.o)
BROKER_REQ_TEST_ESP_BIN=$(BINF)/brokerReqTestEsp

BROKER_REGISTRO_TESTERS_SOURCES=brokerRegistroTesters.cpp
BROKER_REGISTRO_TESTERS_OBJ=$(BROKER_REGISTRO_TESTERS_SOURCES:.cpp=.o)
BROKER_REGISTRO_TESTERS_BIN=$(BINF)/brokerRegistroTesters

BROKER_TESTER_SHMEM_HANDLER_SOURCES=brokerTesterShmemHandler.cpp
BROKER_TESTER_SHMEM_HANDLER_OBJ=$(BROKER_TESTER_SHMEM_HANDLER_SOURCES:.cpp=.o)
BROKER_TESTER_SHMEM_HANDLER_BIN=$(BINF)/brokerTesterShmemHandler

BROKER_FIN_SOURCES=brokerFin.cpp
BROKER_FIN_OBJ=$(BROKER_FIN_SOURCES:.cpp=.o)
BROKER_FIN_BIN=$(BINF)/finBroker

all: initBroker brokerPasamanosEmisor brokerPasamanosReceptor brokerRequerimientosDisp brokerReqTestEsp brokerRegTesters brokerTesterShmemHandler finBroker

initBroker: $(BROKER_OBJ) $(SHARED_OBJ)
	$(CC) $(SHARED_OBJ) $(BROKER_OBJ) -o $(BROKER_BIN) -I$(HEADER_DIR)

brokerPasamanosEmisor: $(BROKER_PASA_MANOS_EMISOR_OBJ) $(SHARED_OBJ)
	$(CC) $(SHARED_OBJ) $(BROKER_PASA_MANOS_EMISOR_OBJ) -o $(BROKER_PASA_MANOS_EMISOR_BIN) -I$(HEADER_DIR)

brokerPasamanosReceptor: $(BROKER_PASA_MANOS_RECEPTOR_OBJ) $(SHARED_OBJ)
	$(CC) $(SHARED_OBJ) $(BROKER_PASA_MANOS_RECEPTOR_OBJ) -o $(BROKER_PASA_MANOS_RECEPTOR_BIN) -I$(HEADER_DIR)

brokerRequerimientosDisp: $(BROKER_REQ_DISP_OBJ) $(SHARED_OBJ)
	$(CC) $(SHARED_OBJ) $(BROKER_REQ_DISP_OBJ) -o $(BROKER_REQ_DISP_BIN) -I$(HEADER_DIR)

brokerReqTestEsp: $(BROKER_REQ_TEST_ESP_OBJ) $(SHARED_OBJ)
	$(CC) $(SHARED_OBJ) $(BROKER_REQ_TEST_ESP_OBJ) -o $(BROKER_REQ_TEST_ESP_BIN) -I$(HEADER_DIR)

brokerRegTesters: $(BROKER_REGISTRO_TESTERS_OBJ) $(SHARED_OBJ)
	$(CC) $(SHARED_OBJ) $(BROKER_REGISTRO_TESTERS_OBJ) -o $(BROKER_REGISTRO_TESTERS_BIN) -I$(HEADER_DIR)

brokerTesterShmemHandler: $(BROKER_TESTER_SHMEM_HANDLER_OBJ) $(SHARED_OBJ)
	$(CC) $(SHARED_OBJ) $(BROKER_TESTER_SHMEM_HANDLER_OBJ) -o $(BROKER_TESTER_SHMEM_HANDLER_BIN) -I$(HEADER_DIR)

finBroker: $(BROKER_FIN_OBJ) $(SHARED_OBJ)
	$(CC) $(SHARED_OBJ) $(BROKER_FIN_OBJ) -o $(BROKER_FIN_BIN) -I$(HEADER_DIR)

.cpp.o:
	$(CC) $(CFLAGS) -I$(HEADER_DIR) -c $< -o $@

clean:
	$(RM) $(BROKER_OBJ) $(BROKER_BIN) $(BROKER_PASA_MANOS_EMISOR_OBJ) $(BROKER_PASA_MANOS_EMISOR_BIN) $(BROKER_PASA_MANOS_RECEPTOR_OBJ) $(BROKER_PASA_MANOS_RECEPTOR_BIN) $(BROKER_REQ_DISP_OBJ) $(BROKER_REQ_DISP_BIN) $(BROKER_REQ_TEST_ESP_OBJ) $(BROKER_REQ_TEST_ESP_BIN) $(BROKER_REGISTRO_TESTERS_OBJ) $(BROKER_REGISTRO_TESTERS_BIN) $(BROKER_TESTER_SHMEM_HANDLER_OBJ) $(BROKER_TESTER_SHMEM_HANDLER_BIN) $(BROKER_FIN_OBJ) $(BROKER_FIN_BIN)